#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <climits>
#include <algorithm> // 添加算法头文件以使用 find

using namespace std;

const int INF = INT_MAX;

int main() {
    int numNodes;
    cin >> numNodes;

    vector<char> nodes(numNodes);
    for (int i = 0; i < numNodes; ++i) {
        cin >> nodes[i];
    }

    cin.ignore(); // 忽略换行符

    // 构建邻接矩阵
    vector<vector<int>> dist(numNodes, vector<int>(numNodes, INF));
    for (int i = 0; i < numNodes; ++i) {
        dist[i][i] = 0;
    }

    string line;
    while (getline(cin, line)) {
        if (line.empty()) break; // 遇到空行停止读取
        istringstream iss(line);
        char u, v;
        int weight;
        iss >> u >> v >> weight;
        int indexU = find(nodes.begin(), nodes.end(), static_cast<char>(u)) - nodes.begin();
        int indexV = find(nodes.begin(), nodes.end(), static_cast<char>(v)) - nodes.begin();
        dist[indexU][indexV] = weight;
        dist[indexV][indexU] = weight; // 无向图，需要双向添加
    }

    // Floyd-Warshall算法计算所有节点之间的最短路径
    for (int k = 0; k < numNodes; ++k) {
        for (int i = 0; i < numNodes; ++i) {
            for (int j = 0; j < numNodes; ++j) {
                if (dist[i][k] != INF && dist[k][j] != INF && dist[i][j] > dist[i][k] + dist[k][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }

    // 找到一个村庄，使得从该村庄到其他所有村庄的最大距离最小
    int minMaxDistance = INF;
    char bestNode;
    for (int i = 0; i < numNodes; ++i) {
        int maxDistance = 0;
        for (int j = 0; j < numNodes; ++j) {
            if (dist[i][j] > maxDistance) {
                maxDistance = dist[i][j];
            }
        }
        if (maxDistance < minMaxDistance) {
            minMaxDistance = maxDistance;
            bestNode = nodes[i];
        }
    }

    // 输出结果
    cout << bestNode << endl;

    return 0;
}